package com.weigee.ktv.view.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.linde.library.activities.MyFragmentActivity
import com.linde.library.util.DisplayUtil
import com.linde.library.util.ToastUtil
import com.weigee.ktv.R
import com.weigee.ktv.model.enums.ImagePreLoad
import com.weigee.ktv.model.enums.WeigeeHost
import com.weigee.ktv.view.interfaces.MainView
import kotlinx.android.synthetic.main.fragment_main_content.*
import skin.support.SkinCompatManager

/**
 * Created by linde on 2017/5/28.
 *<p/>
 */
class MainContentFragment : BaseFragment()
{
    var mainView: MainView? = null

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View?
    {
        val view = inflater?.inflate(R.layout.fragment_main_content, container, false)
        return view
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?)
    {
        super.onViewCreated(view, savedInstanceState)
        DisplayUtil.setStatusBarHeight(frame_top)

        loadImage()
        listener()
    }

    private fun loadImage()
    {
        Glide.with(activity).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(iv_main_top)
        Glide.with(activity).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(iv_portrait)
        Glide.with(activity).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(iv_room_order)
        Glide.with(activity).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(iv_singing)
        Glide.with(activity).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(iv_supermarket)
    }

    private fun listener()
    {
        // 打开/关闭侧滑菜单
        iv_portrait.setOnClickListener({
            mainView?.onChangeLeftDrawerState()
        })
        tv_my_order.setOnClickListener({ v ->
            ToastUtil.show(v, "我的订单")
        })
        iv_room_order.setOnClickListener({ v ->
            //            SnackUtil.show(activity, "包房预定")
            ToastUtil.show(v, "包房预定")
            try
            {
                SkinCompatManager.getInstance().restoreDefaultTheme()
            }
            catch(e: Exception)
            {
                e.printStackTrace()
            }
        })
        iv_singing.setOnClickListener({ v ->
            ToastUtil.show(v, "点歌")
            try
            {
                SkinCompatManager.getInstance().loadSkin("test.skin")
            }
            catch(e: Exception)
            {
                e.printStackTrace()
            }
        })
        iv_supermarket.setOnClickListener({
            MyFragmentActivity.start(activity, AllSupermarketFragment::class.java)
        })
    }
}